﻿using LdtJudge.DataEngine.Common;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using LdtJudge.DataEngine.Model.ElmentModel;
using LdtJudge.DataEngine.Model.XMLConfigModel.OptimzeMode;
using LdtJudge.DataEngine.Model.XMLConfigModel.SameNodeConfigModel;
using System.Collections.Generic;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.BaseModule.MultiFack
{
    public class ModelXmlHandle
    {
        public DataContext dataContext { get; set; }
        /// <summary>
        /// 将分析的结果进行合并
        /// </summary>
        /// <param name="caseCause">案由配置</param>
        /// <param name="list1">被合并的数据集合</param>
        /// <returns></returns>
        public XmlNode ModelToXmlPro(CaseCauseModel caseCause, List<NodeModel> list1)
        {
            XmlDocument xmlDocumentTemplate = new XmlDocument();
            xmlDocumentTemplate.LoadXml(caseCause.ElementXML);
            XmlNode nodetemplate = xmlDocumentTemplate.SelectSingleNode("//事实要素");
            ModelToXml modelToXml = new ModelToXml();
            XmlNode xml2 = modelToXml.BuildXmlNode(list1, caseCause);
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(xml2.OuterXml);
            return xmldoc;
        }

        /// <summary>
        /// 将分析的结果进行合并
        /// </summary>
        /// <param name="caseCause">案由配置</param>
        /// <param name="list1">被合并的数据集合</param>
        /// <param name="xmlMain">需要返回的数据集合</param>
        /// <param name="listCofig">数据配置</param>
        /// <param name="resultxml">返回的节点信息</param>
        /// <returns></returns>
        public void MergeXmlPro(CaseCauseModel caseCause, List<NodeModel> list1, XmlNode xmlMain, List<SameNodeXml> listCofig, XmlNode resultxml)
        {
            XmlDocument xmlDocumentTemplate = new XmlDocument();
            xmlDocumentTemplate.LoadXml(caseCause.ElementXML);
            XmlNode nodetemplate = xmlDocumentTemplate.SelectSingleNode("//事实要素");

            ModelToXml modelToXml = new ModelToXml();
            XmlNode xml2 = modelToXml.BuildXmlNode(list1, caseCause);
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(xml2.OuterXml);
            MultiFactUnion multiFactunion = new MultiFactUnion() ;
            multiFactunion.dataContext = dataContext;
            multiFactunion.MultiFactUnionXml(nodetemplate, xmlMain, xmldoc, listCofig, resultxml,MultiFactBase.SameNodeHandleType.a,true);
        }
    }
}
